//
//  MYViewController.m
//  Travel
//
//  Created by 吴品泽 on 15/4/8.
//  Copyright (c) 2015年 &#21556;&#21697;&#27901;. All rights reserved.
//

#import "MYViewController.h"
#import "MyCell.h"
#import "MySettingViewCell.h"
@interface MYViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;


@property (nonatomic,strong)NSArray *arr1;
@property (nonatomic,strong)NSArray *arr2;
@end

@implementation MYViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.arr1 = @[@"游记",@"专题"];
    self.arr2 = @[@"夜间模式",@"清除缓存",@"意见反馈"];
    [self creatTableView];
}


- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, HIGHT - 108) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.backgroundColor = [UIColor clearColor];
    
    
    //高斯模糊效果
    UIVisualEffectView *visualEffctiView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    
    //创建背景图
    UIImageView *backgroundImage = [[UIImageView alloc]initWithFrame:self.view.bounds];
    backgroundImage.image = [UIImage imageNamed:@"234.jpg"];
    
    //高斯模糊的大小
    visualEffctiView.frame = backgroundImage.bounds;
    
    //给图片添加高斯模糊
    [backgroundImage addSubview:visualEffctiView];
    
    
    
    UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 12)];
    myView.backgroundColor = [UIColor clearColor];
    self.tableView.tableHeaderView = myView;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:backgroundImage];
   [self.view addSubview:self.tableView];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }else{
        return 3;
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        if(indexPath.section == 0){
        
        static NSString *sre = @"buyaoa";
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:sre];
        if (cell == nil) {
            cell = [[MyCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sre];
        }
        
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
        
        cell.setLabel.text = [self.arr1 objectAtIndex:indexPath.row];
        if (indexPath.row == 0) {
            cell.setImageView.image = [UIImage imageNamed:@"iconfont-dianzitushuyuedu.png"];
        }
        
        if (indexPath.row == 1) {
            cell.setImageView.image = [UIImage imageNamed:@"iconfont-remenzhuanti.png"];
        }
        
            return cell;
        
    }else if (indexPath.section == 1){
        
        if (indexPath.row == 0) {
            static NSString *sre = @"setting";
            MyCell *cell = [tableView dequeueReusableCellWithIdentifier:sre];
            
            
            if (cell == nil) {
                cell = [[MyCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sre];
        
            }
            // 从userdefaluts中取值 来判断夜间模式是否开或关闭
            NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
            cell.swich.on = [accountDefaults boolForKey:@"flag"];
            
            
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            cell.setLabel.text = @"夜间模式";
            cell.setImageView.image = [UIImage imageNamed:@"iconfont-yejianzhuanhuan.png"];
           cell.swich.frame = CGRectMake(cell.contentView.frame.size.width - 80, 10, 80, 30);
            cell.TargetAction = self;
            [cell.contentView addSubview:cell.swich];
           
            return cell;
            
            
        }else{
            static NSString *sre = @"buyao2";
            MyCell *cell = [tableView dequeueReusableCellWithIdentifier:sre];
            if (cell == nil) {
                cell = [[MyCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sre];
            }
            
            
            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            
            
            if (indexPath.row == 1) {
                cell.setLabel.text = @"清除缓存";
                cell.setImageView.image = [UIImage imageNamed:@"iconfont-qingchu.png"];
            }
            
            if (indexPath.row == 2) {
                cell.setLabel.text = @"意见反馈";
                cell.setImageView.image = [UIImage imageNamed:@"iconfont-yijianfankui.png"];
            }
            
            return cell;
        }
       
         
    }else{
        
        return nil;
    }
    
    
}

//夜间模式
- (void)changeViewAlph:(UISwitch *)Swith
{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"night" object:nil];
    NSLog(@"呵呵呵");
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        NSString *str = @"我的收藏";
        return str;
    }else{
        
        return @"个性设置";
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
